package com.group3.customer.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class HUCUtil {
	public static String remoteRequest(String Url, String Method) throws IOException {
		URL url = new URL(Url);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		
//		connection.setRequestMethod("GET");
		connection.setRequestMethod(Method);
		
		connection.connect();
		
		int resCode = connection.getResponseCode();
		System.out.println(resCode);
		String result = "";
		if(resCode==200) {
			
			InputStream is = connection.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String line = "";
			while((line=br.readLine())!=null) {
				result += line;
			}
			System.out.println(result);
			
			is.close();
		}
		return result;
	}
}
